import * as ACTION_TYPE from './constant';
const initState = {
	article: {},
	type: 'coding',
	count: 0,
	articleList: [],
	pageNumber: 1,
	pageCount: 10
};

export default (state = initState, action) => {
	const newState = JSON.parse(JSON.stringify(state));
	switch (action.type) {
	case ACTION_TYPE.ARTICLE:
		newState.article = action.value;
		return newState;
	case ACTION_TYPE.ARTICLE_LIST:
		newState.pageNumber = 1;
		newState.count = action.value.count;
		newState.articleList = action.value.list;
		return newState;
	case ACTION_TYPE.ARTICLE_LIST_CHANGE_TYPE:
		newState.pageNumber = 1;
		newState.type = action.value.type;
		newState.count = action.value.data.count;
		newState.articleList = action.value.data.list;
		return newState;
	case ACTION_TYPE.ADD_ARTICLE_LIST:
		newState.pageNumber++;
		newState.count = action.value.count;
		newState.articleList.push(...action.value.list);
		return newState;
	default:
		return state;
	}
};
